package LuoGu.贪心.小A的糖果;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        long ans = 0;
        long check = s.nextInt();
        long [] temp = new long [n];
        for(int i=0;i<n;i++){
            temp[i] = s.nextInt();
        }
        for(int i=0;i<n-1;i++){
            long tempn = temp[i+1]+temp[i];
            if(tempn>check){
                ans+=tempn-check;
                temp[i+1] -= tempn-check;
            }
        }
        System.out.print(ans);
    }
}
